﻿#pragma once

#include "Envir.h"
#include <string>
#include <vector>
#include <cmath>
#include <limits>
#include "../../bankersrounding.h"
#include "../../stringhelper.h"

namespace Server::MirEnvir
{
    class RespawnSave
    {
    public:
        bool Spawned = false;
        unsigned long long NextSpawnTick = 0;
        int RespawnIndex = 0;

        RespawnSave();

        RespawnSave(BinaryReader *reader);

        void Save(BinaryWriter *writer);
    };

    class RespawnTickOption
    {
    public:
        int UserCount = 1;
        double DelayLoss = 1.0;

        RespawnTickOption();

        RespawnTickOption(BinaryReader *reader);

        void Save(BinaryWriter *writer);

        std::string ToString();
    };

    class RespawnTimer
    {
    protected:
        static Server::MirEnvir::Envir *getEnvir();

    public:
        unsigned char BaseSpawnRate = 20; //amount of minutes between respawnticks (with no bonus)
        unsigned long long CurrentTickcounter = 0; //counter used to respawn everything
        long long LastTick = 0; //what 'time' was the last tick?
        int LastUsercount = 0; //stops it from having to check delay each time
        long long CurrentDelay = 0;
        std::vector<RespawnTickOption*> Respawn = std::vector<RespawnTickOption*>();

        RespawnTimer();

        RespawnTimer(BinaryReader *reader);
        void Save(BinaryWriter *writer);


        void Process();

        void GetTickSpeed();
    };
}
